﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace websitev2.Controllers
{
    public class AwardController : Controller
    {
        //
        // GET: /Awards/

        public Models.StartStopEntities db = new Models.StartStopEntities(); 

        public ActionResult Index()
        {
            return View();
        }

        public ActionResult Trophies()
        {
            var alltrophies = StartStop.Helpers.Trophy.ListOfTrophies();  

            return View(alltrophies); 
        }

        public ActionResult Trophy(string ID)
        {
            int _trophyID = 1; 
            try
            {
                 _trophyID = Int32.Parse(ID);
            }
            catch
            {
            }
            var trophy = StartStop.Helpers.Trophy.LoadTrophy(_trophyID);
            
            // Get all the users with trophy
            // ** We may want to limit the number of rows for this. 
            ViewBag.UsersTrophy = Core.TrophyCore.UsersWithTrophy(_trophyID, true,6);
            ViewBag.USersTrophyProgress = Core.TrophyCore.UsersWithTrophy(_trophyID, false,6);

            // if there are users with this trophy then add the count
            if (ViewBag.UsersTrophy != null)
            {
                ViewBag.UserAwardedCount = ViewBag.UsersTrophy.Length; 
            }
            else
            {
                ViewBag.UserAwardedCount = "0"; 
            }

            StartStop.ServiceResources.MessageResponse oResponse = StartStop.Helpers.Trophy.ApplicationAssociatedWithTrophy(_trophyID);
            if (oResponse.Success)
            {
                
                ViewBag.AppLink = oResponse; 
            }


            #region SEO
            ViewBag.Title =trophy.Name + ", "+ trophy.Description + " | Startstop.me, all your stats in one place"; 
            #endregion 

            return View(trophy); 
        }

    }
}
